<template>
<div style="width: 100%">
  <a-card class="card" :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="vertical">
        <a-row :gutter="48">
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}" >
            <a-form-item label="院系">
              <a-select :disabled="selectMenu.yx.length === 1" :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.bkyxsm" @change="yxChange">
                <a-select-option v-for="i in selectMenu.yx" :key="i.id" :value="i.dwh">{{i.dwh+"-"+  i.dwmc }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="专业">
              <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.bkzydm" @change="zyChange">
                <a-select-option v-for="i in selectMenu.zy" :key="i.id" :value="i.zyh">{{ i.zyh+'-'+i.zymc }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}" >
            <a-form-item label="研究方向">
            <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.bkyjfxm">
            <a-select-option v-for="i in selectMenu.fx" :key="i.id" :value="i.yjfxm">{{ i.yjfxm.substring(i.yjfxm.length-2) +"-"+ i.yjfxmc }}</a-select-option>
            </a-select>
          </a-form-item>
              </a-col>
          <template v-if="advanced">
          <a-col :sm="{span:24}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="招生年度">
              <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.zsnj">
                <a-select-option v-for="i in TYPE0126" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
           <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="学习形式">
              <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.zhxlxxxs">
                <a-select-option v-for="i in selectMenu.xxlx" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          </template>
          <a-col :sm="{span:16}" :xl="{span:24}">
            <span class="table-page-search-submitButtons">
            <a-button type="primary" @click="loadData" >查询</a-button>
            <a-button type="primary" @click="handlePrint">专业打印</a-button>
            <a-button type="primary" @click="handleFxPrint">研究方向打印</a-button>
            <a-button @click="queryParam = {};loadData()" >重置</a-button>
            <a @click="advanced = !advanced" style="margin-left: 8px">
                {{ advanced ? '收起' : '展开' }}
                <a-icon :type="advanced ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    </a-card>
    <a-card class="card" :bordered="false">
      <a-alert :message="'总条数：' + pagination.total" type="info" show-icon />
      <a-table
        ref="table"
        size="default"
        rowKey="key"
        :columns="columns"
        :loading="loading"
        :dataSource="data"
        :pagination="pagination"
        @change="handleTableChange"
      >
        <span slot="serial" slot-scope="text, record, index">
          {{ index + 1 }}
        </span>
      </a-table>
    </a-card>
</div>
</template>

<script>
// import moment from 'moment'
import { STable } from '~'
import { mapState } from 'vuex'

const selectArr = ['TYPE0126', 'TYPE0075', 'TYPE0125', 'TYPE0072']

export default {
  name: 'Sort',
  components: {
    STable
  },
  data () {
    return {
      advanced: true,
      fileList: [],
      uploading: false,
      loading: false,
      data: [],
      // 查询参数
      queryParam: {
        zhxlxxxs: '',
        bkyxsm:'',
        bkzydm:'',
        zhxlxxxs:''
      },
      postParams: {},
      // 表头
      columns: [
        {
          title: '序号',
          scopedSlots: { customRender: 'serial' }
        },
        {
          title: '准考证号',
          dataIndex: 'ksbh'
        },
        {
          title: '姓名',
          dataIndex: 'ksxm'
        },
        {
          title: '指导老师',
          dataIndex: 'bkdsyxm'
        },
        {
          title: '录取类别',
          dataIndex: 'lqlbm'
        },
        {
          title: '初试总成绩',
          dataIndex: 'zf'
        },
        {
          title: '初试成绩权重',
          dataIndex: 'cscjqz'
        },
        {
          title: '复试成绩（百分制）',
          dataIndex: 'fscj'
        },
        {
          title: '复试成绩权重',
          dataIndex: 'fscjqz'
        },
        {
          title: '综合考试成绩（百分制）',
          dataIndex: 'zhpd'
        },
        {
          title: '是否拟录取',
          dataIndex: 'lqzt'
        }
      ],
      recruitAddVisiable: false,
      recruitEditVisiable: false,
      selectMenu: {
        yx: [] ,// 院系
        xxlx:[],
        zy:[]
      },
      recruitEditData: {},
      pagination:{
        current:1,
        showTotal: (() => {return `共 ${this.pagination.total} 条`}),
        showSizeChanger: true,
        pageSizeOptions: ['10', '50', '100'],
            // 改变pageSize后触发
        onShowSizeChange: (current, pageSize) => this.pagination.pageSize = pageSize,
        showTotal: (() => {return `共 ${this.pagination.total} 条`})
      }
    }
  },
  computed: {
    ...mapState({
      systemInfo: state => state.app.systemInfo,
      TYPE0307: state => state.app['TYPE0307'], // 学习形式
      TYPE0126: state => state.app['TYPE0126'] // 年级
    })
  },
  created () {
    this.initSelectMenu()
    selectArr.forEach(v => {
      this.$store.dispatch('app/setDictionary', v)
    })
  },
  methods: {
    initSelectMenu () {
      let allRequest = [
        this.$api.base.collegeAll(),
        this.$api.base.getSchoolYear(),
        this.$api.base.dictionaryData('TYPE0441')
      ]
      Promise.all(allRequest).then(res => {
        this.selectMenu = {
          yx: res[0].data
        }
        this.queryParam.bkyxsm = res[0].data[0].dwh
             // 获取学习形式
          this.selectMenu.xxlx = res[2].data
          this.getProssion(this.queryParam.bkyxsm)
           // 获取当前学年
           this.$set(this.queryParam,'zsnj',res[1].data.masterAdmissionYear)
           this.loadData({
            pageNum:1,
            pageSize:10
          })
        })
    },
    // 选择院系
     yxChange (code) {
       this.$set(this.queryParam, 'zszym', '')
       this.$set(this.selectMenu, 'zy', [])
       if(code){

        this.getProssion(code)
       }
     },
     getProssion(code){
       this.$api.base.majorAll({lsdwh: code}).then(res => {
         this.$set(this.selectMenu, 'zy', res.data)
       })
     },
     zyChange(code){
       this.$set(this.queryParam, 'bkyjfxm', '')
        this.$set(this.selectMenu, 'fx', [])
        if(code){
          this.getDurection(code)
        }
    },
    getDurection(code) {
        this.$api.base.searchDirectory({
          ssyxm: this.queryParam.bkyxsm,
          zsxn: this.queryParam.zsnj,
          sszym: code,
           xwccm: 2
        }).then(res => {
          this.$set(this.selectMenu, 'fx', res.data)
        })
      },
       // 加载数据
     loadData (parameter = {}) {
        if(!parameter.pageNum){
         this.pagination.current = 1
         parameter.pageNum = 1
       }
       let params = Object.assign(this.queryParam, parameter)
          this.loading = true
         this.$api.recruitstat.compreRankOfReexamList(params).then(res=>{
             const pagination = { ...this.pagination
            };
            pagination.total = 0
            if (res.data && res.data.total) {
              pagination.total = res.data.total;
            }
            this.data = []
            this.pagination = pagination;
            if (res.data && res.data.rows.length) {
              res.data.rows.map(function(item,index){
                if(item.cscjqz){
                  item.cscjqz = item.cscjqz +'%'
                }
                if(item.fscjqz){
                  item.fscjqz = item.fscjqz +'%'
                }
              })
              this.data = res.data.rows;
            }
            this.loading = false;
         })
         console.log(this.data)
     },
     // 分页
     handleTableChange (pagination, filters, sorter) {
      console.log(pagination);
      const pager = { ...this.pagination };
      pager.current = pagination.current;
      this.pagination = pager;
      this.loadData({
        pageSize: pagination.pageSize,
        pageNum: pagination.current
      });
   },
    // 选择招生年度
    zsndChange () {

    },
    // 打印
    handlePrint () {
      console.log('打印')
      this.$export("admissions/fslqzhpx/export",this.queryParam)
    },
    handleFxPrint(){
      this.$export("admissions/fslqzhpx/yjfxExport",this.queryParam)
    }
  }
}
</script>

<style lang="less" scoped>
.card{
  margin-bottom: 20px;
}
</style>
